package com.cman777.springc.ratelimiter;


import com.cman777.springc.ratelimiter.interceptor.ServletInterceptor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author chenzhicong
 * @time 2020/9/18 16:20
 */
@Configuration
public class RateLimiterAutoConfig {
    @ConditionalOnBean(RateLimiterClient.class)
    @Bean
    @SuppressWarnings("all")
    public ServletInterceptor servletInterceptor4RateLimit(RateLimiterClient rateLimiterClient) {
            return new ServletInterceptor(rateLimiterClient);
    }

    @ConditionalOnBean(RateLimiterClient.class)
    @Bean
    @SuppressWarnings("all")
    public ReloadRulesTask reloadRatelimitRulesTask(RateLimiterClient rateLimiterClient) {
        return new ReloadRulesTask(rateLimiterClient);
    }
}
